package com.alibaba.algo.controller.user;

import com.alibaba.algo.apiimpl.user.SysUserRoleServiceImpl;
import com.alibaba.algo.cooperation.common.BaseResult;
import com.alibaba.algo.cooperation.usercenter.GlobalResultStatus;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SelectRoleListByUserRequestVO;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SelectUserRoleRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类SysUserRoleController.java的实现描述：用户角色关联 Controller
 *
 * @author nieganggang 2021-03-12 16:08:17
 */
@RestController
@RequestMapping(value = "/usercenter-admin-app/admin/sysUserRole")
public class SysUserRoleController {

    @Autowired
    private SysUserRoleServiceImpl sysUserRoleService;

    @PostMapping("/selectPage")
    public BaseResult insert(@RequestBody SelectUserRoleRequestVO vo) {
        if (ObjectUtils.isEmpty(vo.getPageIndex())) {
            return BaseResult.buildError(GlobalResultStatus.PARAM_PAGE_INDEX_ERROR.getCode(), GlobalResultStatus.PARAM_PAGE_INDEX_ERROR.getMsg());
        }
        if (ObjectUtils.isEmpty(vo.getPageSize())) {
            return BaseResult.buildError(GlobalResultStatus.PARAM_PAGE_SIZE_ERROR.getCode(), GlobalResultStatus.PARAM_PAGE_SIZE_ERROR.getMsg());
        }
        return BaseResult.buildSuccess(sysUserRoleService.selectPage(vo));
    }

    @PostMapping("/selectRoleCodeByUser")
    public BaseResult selectRoleCodeByUser(@RequestBody SelectRoleListByUserRequestVO vo){
        if (StringUtils.isEmpty(vo.getAppCode())){
            return BaseResult.buildError(GlobalResultStatus.PARAM_APP_CODE_ERROR.getCode(),GlobalResultStatus.PARAM_APP_CODE_ERROR.getMsg());
        }
        if (null == vo.getUserId()){
            return BaseResult.buildError(GlobalResultStatus.PARAM_USER_ID_ERROR.getCode(),GlobalResultStatus.PARAM_USER_ID_ERROR.getMsg());
        }
        return BaseResult.buildSuccess(sysUserRoleService.selectRoleCodeByUser(vo));
    }

}
